﻿var CurrentAd = {};

Ext.onReady(function () {
    PageSafe();

    //未审核广告
    var adstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('Advertisement.AdvertisementView', 'GetFlowDoc'),
        root: 'ResponseObject',
        fields: ['PID', 'DocName', 'DocPrice', 'DocCustom', 'IsGoods', 'GoodsCount', 'GoodsName', 'Remark', 'MoreInfo', 'UserID', 'DocState', 'DState', 'LastUpdate', 'NTime', 'FlowPID', 'FlowID', 'PersonID', 'NodeID', 'ContentID', 'FlowLastUpdate'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    var adsm = new Ext.grid.CheckboxSelectionModel({
        singleSelect: true,
        listeners: {
            rowselect: function () {
                var k = adgrid.getSelectionModel().selections.items;
                if (k.length > 0) {
                    CurrentAd = k[0].json;
                }
            },
            rowdeselect: function () {
                CurrentAd = {};
            }
        }
    });
    var adgrid = new Ext.grid.GridPanel({
        bodyStyle: 'padding:2px',
        border: false,
        split: true,
        height: 500,
        sm: adsm,
        loadMask: true, //加载
        columns: [
       adsm,
       { id: 'DocName', header: '申请单名称', width: 100, dataIndex: 'DocName', sortable: true },
       { id: 'DocPrice', header: '价格', width: 60, dataIndex: 'DocPrice', sortable: true },
       { id: 'DocCustom', header: '客户名称', width: 100, dataIndex: 'DocCustom', sortable: true },
       { id: 'IsGoods', header: '是否物品', width: 80, dataIndex: 'IsGoods', sortable: true },
       { id: 'GoodsName', header: '物品名称', width: 80, dataIndex: 'GoodsName', sortable: true },
       { id: 'GoodsCount', header: '数量', width: 60, dataIndex: 'GoodsCount', sortable: true },
        { id: 'DState', header: '状态', width: 60, dataIndex: 'DState', sortable: true },
       { id: 'NTime', header: '日期', width: 100, dataIndex: 'NTime', sortable: true },
       { id: 'NTime', header: '查看', width: 100, dataIndex: '', sortable: true, renderer: function () {
           return '<a href="#" onclick="DownDoc();">下载查看</a>';
       } 
       }
   ],
        store: adstore
    });


    var page = new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            title: '申请单流程审核',
            iconCls: 'flow-icon',
            layout: 'border',
            items: [{
                region: 'center',
                style: 'padding:2px',
                title: '等待审核的申请单',
                items: adgrid
            }, {
                region: 'south',
                title: '审核操作',
                style: 'padding:2px',
                height: 160,
                layout: 'table',
                defaults: {
                    // 对每一个子面板都有效applied to each contained panel
                    style: 'padding:20px'
                },
                layoutConfig: {
                    // 这里指定总列数The total column count must be specified here
                    columns: 2
                },

                items: [{
                    rowspan: 2,
                    xtype: 'textfield',
                    id: 'content',
                    height: 60,
                    width: 300
                }, {
                    xtype: 'button',
                    text: '通过',
                    handler: function () {
                        if (CurrentAd.PID == null) { Ext.Msg.alert("提示信息", "请选择需要审核的申请单"); return; }
                        var re = new JsonRequest();
                        re.params.info = CurrentAd;
                        re.params.c = Ext.getCmp("content").getValue();
                        Ext.Ajax.request({
                            url: Ext.getClassUrl('Advertisement.AdvertisementView', 'PassFlowDoc'),
                            jsonData: re,
                            success: function (re, op) {
                                var obj = Ext.decode(re.responseText);
                                if (!obj.HasError) {
                                    Ext.Msg.alert("提示信息", "申请单审核成功");
                                    adstore.load();
                                }
                                else {
                                    Ext.Msg.alert("提示信息", "申请单审核失败，请联系管理员");
                                }
                            }
                        });
                    }
                }, {
                    xtype: 'button',
                    text: '拒绝',
                    handler: function () {
                        if (CurrentAd.PID == null) { Ext.Msg.alert("提示信息", "请选择需要审核的申请单"); return; }
                        var re = new JsonRequest();
                        re.params.info = CurrentAd;
                        re.params.c = Ext.getCmp("content").getValue();
                        Ext.Ajax.request({
                            url: Ext.getClassUrl('Advertisement.AdvertisementView', 'RejectFlowDoc'),
                            jsonData: re,
                            success: function (re, op) {
                                var obj = Ext.decode(re.responseText);
                                if (!obj.HasError) {
                                    Ext.Msg.alert("提示信息", "申请单审核成功");
                                    adstore.load();
                                }
                                else {
                                    Ext.Msg.alert("提示信息", "申请单审核失败，请联系管理员");
                                }
                            }
                        });
                    }
                }]
            }]
        }],
        listeners: {
            render: function () {
                adstore.load();
            }
        }
    });
});

var DownDoc = function () {
    window.open("../" + CurrentData.MoreInfo);
}